package org.springblade.auth.utils;

import cn.hutool.http.HttpRequest;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author dengzhongtao
 * @date 2022-01-21
 */
@Component
public class CasUtil {
	@Value("${cas.client-logout-url}")
	public String url;

	@Value("${cas.server-host-url}")
	public String server;

	public Map<String,Object> getCasInfo(){
		Map<String,Object> map = new HashMap<>();
		map.put("url",this.url);
		return map;
	}

	public boolean sendMessage(String userTicket,String token){
		Map<String,Object> map = new HashMap<>();
		map.put("url",this.url);
		map.put("userTicket",userTicket);
		map.put("token",token);
		String body = HttpRequest.post(this.server)
			.form(map)
			.timeout(20000)
			.execute().body();
		if ("true".equals(body)){
			return true;
		}
		return false;
	}

}
